package com.qumap.map.impl;

import com.google.gwt.core.client.GWT;
import com.google.gwt.maps.client.HasMap;
import com.google.gwt.maps.client.MapOptions;
import com.google.gwt.maps.client.MapTypeId;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.base.HasLatLng;
import com.google.gwt.maps.client.base.LatLng;
import com.google.gwt.maps.client.overlay.*;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.qumap.map.IMapView;


/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: 06.05.11
 * Time: 15:47
 * To change this template use File | Settings | File Templates.
 */
public class SimpleMap implements IMapView {

	final private static String MAP_TYPE = new MapTypeId().getRoadmap();

	private MapWidget map;
	private Widget root;


	interface SimpleMapUiBinder extends UiBinder<Widget, SimpleMap> {}

	private static SimpleMapUiBinder ourUiBinder = GWT.create(SimpleMapUiBinder.class);

	@UiField
	SimplePanel mapWrapper;

	public SimpleMap() {
		root = ourUiBinder.createAndBindUi(this);
		createMap();
	}

	private void createMap() {
		final MapOptions options = new MapOptions();
		options.setZoom(8);
		options.setCenter(new LatLng(50.425, 30.422));
		options.setMapTypeId(MAP_TYPE);
		options.setDraggable(true);
		options.setNavigationControl(true);

		map = new MapWidget(options);

		map.setSize("700px", "800px");
		mapWrapper.add(map);
	}

	@Override
	public HasLatLng createLatLng(double lat, double lng) {
		return new LatLng(lat, lng);
	}

    @Override
    public String getInactiveStateImageURL() {
        return "/recources/load_icon.gif";
    }

    @Override
	public HasMap getMap() {
		return map.getMap();
	}

	@Override
	public HasMarker createMarker() {
		return new Marker();
	}


	@Override
	public Widget asWidget() {
		return root;
	}


}